package userServlet;

import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import userDao.UserDao;
import userEntity.User;
import userImplment.UserImplement;

/**
 * Servlet implementation class ChangePassWord
 */
public class ChangePassWord extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public ChangePassWord() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		String passWord = request.getParameter("passWord");
		String newpassWord = request.getParameter("newPassWord");
		HttpSession session = request.getSession();
		PrintWriter out=response.getWriter();
		User user=(User)session.getAttribute("user");
		if(user!=null){
			UserDao userImplement=new UserImplement();
			if(userImplement.ChangePassWord(user.getId(), passWord, newpassWord)) {
				session.invalidate();//修改成功销毁session，跳转到首页重新登录
				out.write("true");
			}else {
                out.write("false");
			}
		}else{
			out.write("null");
		}

	    
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
